<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: input_fields.php 59 2013-09-21 11:58:47Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 59 $
* 	zuletzt geaendert von:	$Author$
* 	Datum:					$Date: 2013-09-21 11:58:47 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php'); 

function checkbox($value = '', $checked = false) {
	if($value == 1 && $checked)
		return ' checked=""';
	elseif($value == 0 && $checked)
		return '';
	elseif(empty($value))
		return 0;
	elseif(!empty($value))
		return 1;
}

if(isset($_GET['action']) && $_GET['action'] == 'save') {
	
	$get_data = $db->db_query("SELECT
									field_name
								FROM 
									".TABLE_INPUT_FIELDS);
					
	while(!$get_data->EOF) {
		
		$sql = array('show_create_account' => checkbox($_POST['show_create_account'][$get_data->fields['field_name']]),
					'require_create_account' => checkbox($_POST['require_create_account'][$get_data->fields['field_name']]),
					'show_create_guest_account' => checkbox($_POST['show_create_guest_account'][$get_data->fields['field_name']]),
					'require_create_guest_account' => checkbox($_POST['require_create_guest_account'][$get_data->fields['field_name']]),
					'min_length' => $_POST['min_length'][$get_data->fields['field_name']],
					'max_length' => $_POST['max_length'][$get_data->fields['field_name']],
					'error_desc' => $_POST['error_desc'][$get_data->fields['field_name']]);
		
		$db->db_perform(TABLE_INPUT_FIELDS, $sql, 'update', "field_name = '".$get_data->fields['field_name']."'");
		$get_data->MoveNext();
	}
	$message_stack->add_session(TEXT_INPUT_FIELDS_SAVED, 'success');
	redirect(href_link('input_fields.php'));
}

require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
	<table class="outerTable" cellspacing="0" cellpadding="0">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
			</td>
			<td class="boxCenter" height="100%" valign="top">
	        	<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		   			<tr>
		     			<td class="pageHeading">Eingabe Felder</td>
					</tr>
				</table>
				<?php echo draw_form('save_values', 'input_fields.php', 'action=save'); ?>
		        	<table width="100%" class="dataTable">
		        		<tr class="dataTableHeadingRow">
		        			<th>Feldname</th>
		        			<th>anzeigen<br />Kontoerstellung</th>
		        			<th>Pflicht<br />Kontoerstellung</th>
		        			<th>anzeigen<br />Gast-Kontoerstellung</th>
		        			<th>Pflicht<br />Gast-Kontoerstellung</th>
		        			<th>mindest Länge</th>
		        			<th>maximal Länge</th>
		        			<th>Fehler Konstante</th>
		        		</tr>
		        		<?php
		        			$get_data = $db->db_query("SELECT
		        											field_name,
		        											show_create_account AS sca,
		        											require_create_account AS rca,
		        											show_create_guest_account AS scga,
		        											require_create_guest_account AS rcga,
		        											min_length,
		        											max_length,
		        											error_desc
		        										FROM 
		        											".TABLE_INPUT_FIELDS);
		        			while(!$get_data->EOF) {
		        				$c .= '	<tr>';
		        				$c .= '		<td>'.constant(strtoupper($get_data->fields['field_name']).'_TITLE').'</td>';
		        				$c .= '		<td align="center">
		        								<input type="checkbox" name="show_create_account['.$get_data->fields['field_name'].']"'.checkbox($get_data->fields['sca'], true).' value="1" />
		        							</td>';
		        				$c .= '		<td align="center">
		        								<input type="checkbox" name="require_create_account['.$get_data->fields['field_name'].']"'.checkbox($get_data->fields['rca'], true).' value="1" />
		        							</td>';
		        				$c .= '		<td align="center">
		        								<input type="checkbox" name="show_create_guest_account['.$get_data->fields['field_name'].']"'.checkbox($get_data->fields['scga'], true).' value="1" />
		        							</td>';
		        				$c .= '		<td align="center">
		        								<input type="checkbox" name="require_create_guest_account['.$get_data->fields['field_name'].']"'.checkbox($get_data->fields['rcga'], true).' value="1" />
		        							</td>';
		        				$c .= '		<td align="center">
		        								<input type="text" size="5" name="min_length['.$get_data->fields['field_name'].']"'.checkbox($get_data->fields['rcga'], true).' value="'.$get_data->fields['min_length'].'" />
		        							</td>';
		        				$c .= '		<td align="center">
		        								<input type="text" size="5" name="max_length['.$get_data->fields['field_name'].']"'.checkbox($get_data->fields['rcga'], true).' value="'.$get_data->fields['max_length'].'" />
		        							</td>';
		        				$c .= '		<td align="center">
		        								<input type="text" style="width:98%" name="error_desc['.$get_data->fields['field_name'].']" value="'.$get_data->fields['error_desc'].'" />
		        							</td>';
		        				$c .= '	</tr>';
		        				$get_data->MoveNext();
		        			}
		        			echo $c;
		        		?>
		        	</table>
		        	<button class="button" type="submit"><span class="button_disk-black"><?php echo BUTTON_SAVE; ?></span></button>
		        </form>
		    </td>
		</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>